package com.base.cn.platform.os.controller.manage.join;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.entity.manage.join.SysRoleSubject;
import com.base.cn.platform.os.service.manage.join.SysRoleSubjectBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * 角色与专业的关联Controller
 *
 * @author s.li
 * @create 2018-03-21 14:28
 */
@RestController
@RequestMapping("/manage")
public class SysRoleSubjectController extends BaseController {

    @Autowired
    private SysRoleSubjectBiz sysRoleSubjectBiz;

    /**
     * 获取角色关联的专业列表数据
     * @param roleId 角色ID
     * @return 数据列表
     */
    @RequestMapping("/findRoleSubjectList")
    public List<SysRoleSubject> findRoleSubjectList(@RequestParam("roleId")BigDecimal roleId){
        return sysRoleSubjectBiz.find(" roleId = "+roleId,null,null);
    }

    /**
     * 管理用户登录成功后台缓存用户的专业权限
     * @param sin 登录KEY
     * @param userId 登录的用户ID
     */
    @RequestMapping("/cacheSysUserSubjectData")
    public void cacheSysUserSubjectData(@RequestParam(value = "sin",required = false,defaultValue = "") String sin,
                                        @RequestParam(value = "userId",required = false,defaultValue = "0") BigDecimal userId){
        if(StringUtils.isNotEmpty(sin) && DataUtil.idIsNotNull(userId)){
            sysRoleSubjectBiz.cacheSysUserSubjectData(sin,userId);
        }
    }
}
